using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.PlayerController;

namespace Yoozoo.Gameplay.Liberty.AI
{
    public class DynamicNpcManager : MonoBehaviour
    {
        private AIEntity PlayerEntity => LibertyAIUtils.GetPlayerEntity();
        private PlayerControlModeMgr PlayerController => LibertyAIUtils.PlayerController;
        
        [SerializeField]
        private List<int> entityIdList;
        
        public bool AddDynamicNpc(AIBirthData birthData)
        {
            if (GetAIEntity(birthData.uniqueId)!=null)
            {
                return false;
            }
            birthData.isStatic = false;
            bool success = LibertyAIUtils.AIManager.AddNpc(birthData);
            return success;
        }

        public bool AddDynamicNpc(AIBirthData birthData, int graphId)
        {
            if (GetAIEntity(birthData.uniqueId)!=null)
            {
                return false;
            }
            
            birthData.isStatic = false;
            bool success = LibertyAIUtils.AIManager.AddNpc(birthData,graphId);
            return success;
        }

        public bool RemoveDynamicNpc(int uniqueId)
        {
            bool success = LibertyAIUtils.AIManager.RemoveNpc(uniqueId);
            return success;
        }

        public AIEntity GetDynamicNpc(int uniqueId)
        {
            if (entityIdList == null || !entityIdList.Contains(uniqueId))
            {
                return null;
            }
            return GetAIEntity(uniqueId);
        }

        private AIEntity GetAIEntity(int uniqueId)
        {
            return LibertyAIUtils.AIManager.NpcBirthManager.GetNpc(uniqueId);
        }


        public void Dispose()
        {
            entityIdList.Clear();
        }
    }
}